package com.itheima.dao;

import com.itheima.domain.Member;
import com.itheima.domain.Orders;
import com.itheima.domain.Product;
import com.itheima.domain.Traveller;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface OrdersMapper {
 @Results(id = "ordersMap",value = {
         @Result(id = true,column = "id",property = "id"),
         @Result(column = "orderTime",property = "orderTimeStr"),
         @Result(column = "orderTime",property = "orderTime"),
         @Result(column = "memberId",property = "memberId"),
         @Result(column = "productId",property = "productId"),
         @Result(
                 property = "member",   // 被包含对象的变量名
                 javaType = Member.class,  // 被包含对象的实际数据类型
                 column = "memberId",          // 根据查询出student表的id来作为关联条件，去查询中间表和课程表
                 one = @One(select = "com.itheima.dao.OrdersMapper.selectByOidm",fetchType = FetchType.LAZY)
         ),// many、@Many 一对多查询的固定写法select属性：指定调用哪个接口中的哪个查询方法
         @Result(
                 property = "travellers",   // 被包含对象的变量名
                 javaType = List.class,  // 被包含对象的实际数据类型
                 column = "id",          // 根据查询出student表的id来作为关联条件，去查询中间表和课程表
                 many = @Many(select = "com.itheima.dao.OrdersMapper.selectByOidt",fetchType = FetchType.LAZY)
         ),
         @Result(
                 property = "product",   // 被包含对象的变量名
                 javaType = Product.class,  // 被包含对象的实际数据类型
                 column = "productId",          // 根据查询出student表的id来作为关联条件，去查询中间表和课程表
                 one = @One(select = "com.itheima.dao.OrdersMapper.selectByOidp",fetchType = FetchType.LAZY)
         )
 })
    @Select("select * from orders")
    List<Orders> findAll();

 @ResultMap("ordersMap")
 @Select("select * from orders where id=#{id}")
    Orders findByOid(String id);

    void deleteByIds(String[] split);

    void deleteo_dByOids(String[] split);


    @Select("select * from member where id=#{id}")
    Member selectByOidm(String id);

    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "departureTime",property = "departureTimeStr"),
            @Result(column = "departureTime",property = "departureTime"),
    })
    @Select("select * from product where id=#{id}")
    Product selectByOidp(String id);

    @Select("SELECT * from traveller t " +
            " WHERE  t.id in (SELECT ot.travellerId from  order_traveller ot" +
            " where  ot.orderId =#{id})")
    List<Traveller> selectByOidt(String id);


    List<Orders> findAllByLike(String dd);
}
